package com.jm.controller;

import com.jm.domain.ResponseResult;
import com.jm.domain.entity.Menu;
import com.jm.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public ResponseResult list(String status,String menuName){
        return menuService.listMenu(status,menuName);
    }

    @GetMapping("/{id}")
    public ResponseResult getMenuById(@PathVariable Long id){
        return menuService.getMenuById(id);
    }

    @PostMapping
    public ResponseResult save(@RequestBody Menu menu){
        return menuService.saveMenu(menu);
    }

    @PutMapping
    public ResponseResult updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteMenuById(@PathVariable Long id){
        return menuService.deleteMenuById(id);
    }

    @GetMapping("/treeselect")
    public ResponseResult treeSelectMenu(){
        return menuService.treeSelectMenu();
    }

    @GetMapping("/roleMenuTreeselect/{roleId}")
    public ResponseResult roleMenuTreeselect(@PathVariable Long roleId){
        return menuService.treeSelectMenuByRoleId(roleId);
    }
}
